<?php

class Control_Forum_Threads extends QUI_Control_Abstract
{
    function render()
    {
        $order  = $this->_extract('order', 'dateline DESC');
        $length = $this->_extract('length', Q::ini('appini/homepage/forum_threads_length'));
        $where  = $this->_extract('where');
        $fids   = Q::normalize($this->_extract('fids'));

        $select = Forum_Thread::find()->order($order)->top($length);
        if (!empty($fids))
        {
            $select->where('fids in (?)', $fids);
        }
        if (!empty($where))
        {
            call_user_func_array(array($select, 'where'), (array)$where);
        }

        $this->_view['threads'] = $select->query();
        $this->_view['label']   = $this->label;
        $this->_view['width']   = $this->_extract('width', 34);
        $this->_view['icons']   = $this->icons;
        $this->_view['thread_view_url'] = Q::ini('appini/forum/thread_view_url');
        return $this->_fetchView(dirname(__FILE__) . '/threads_view.php');
    }
}


